package com.heima.wemedia.config;


import com.heima.common.constants.message.PublishArticleConstants;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DeclarePubArticleRabbitConfig {

    //声明交换机
    @Bean
    public DirectExchange delayDirect(){
        return ExchangeBuilder.directExchange(PublishArticleConstants.DELAY_DIRECT_EXCHANGE)
                                .delayed()   //设置延迟交换机
                                .build();
    }

    //声明队列
    @Bean
    public Queue queue(){
        return new Queue(PublishArticleConstants.PUBLISH_ARTICLE_QUEUE);
    }


    //绑定关系
    @Bean
    public Binding binding(){
        return BindingBuilder.bind(queue()).to(delayDirect())
                            .with(PublishArticleConstants.PUBLISH_ARTICLE_ROUTE_KEY);
    }
}
